package P150;

/**
 * @author LiangMu
 * @version \$Id: P22.java, v 0.1, 2024年07月05日 14:05 LiangMu Exp $$
 */
public class P22 {

    public int strStr(String haystack, String needle) {
        if (needle.length() > haystack.length()) {
            return -1;
        }

        char[] source = haystack.toCharArray();
        char[] target = needle.toCharArray();
        out:
        for (int i = 0; i < source.length - target.length; i++) {
            if (source[i] != target[0]) {
                continue;
            }
            for (int i1 = 0; i1 < target.length; i1++) {
                if (source[i1 + i] != target[i1]) {
                    continue out;
                }
            }
            return i;
        }
        return -1;
    }
}
